//
//  HotViewcontroller.m
//  YSBEmployee
//
//  Created by developer on 2021/11/30.
//  Copyright © 2021 ysb. All rights reserved.
//

#import "YSBChildOrderDetailViewController.h"
#import "YSBChildWaitingOrderDetailViewController.h"

#import "IntroductoryPagesHelper.h"

#import "IntroductoryPagesView.h"


@implementation YSBChildOrderDetailViewController

- (void)showNewbieGuideDetail {
    NSArray *images = @[@"OrderDetail_5.5"];
    NSArray *btnTitles = @[@"我知道了"];
    IntroductoryPagesHelper *helper = [[IntroductoryPagesHelper alloc] init];
    [helper showNewIntroductoryPageView:images andBtnTitles:btnTitles andType:105];
}

@end


@implementation YSBChildWaitingOrderDetailViewController

- (void)showNewbieGuideDetail {
    NSArray *images = @[@"OrderDetail_5.5"];
    NSArray *btnTitles = @[@"我知道了"];
    IntroductoryPagesHelper *helper = [[IntroductoryPagesHelper alloc] init];
    [helper showNewIntroductoryPageView:images andBtnTitles:btnTitles andType:105];
}

@end


@interface IntroductoryPagesHelper : NSObject

- (void)showNewIntroductoryPageView:(NSArray *)imageArray andBtnTitles:(NSArray *)btnTitles andType:(NSInteger)guideType;

@end


@implementation IntroductoryPagesHelper

- (void)showNewIntroductoryPageView:(NSArray *)imageArray andBtnTitles:(NSArray *)btnTitles andType:(NSInteger)guideType {
    if (!self.curIntroductoryPagesView) {
        self.curIntroductoryPagesView = [[IntroductoryPagesView alloc] initNewPagesViewWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) Images:imageArray andBtnTitles:btnTitles andType:guideType];
    }
    
    self.rootWindow = [YSBCommonTool keyWindow];
    [self.rootWindow addSubview:self.curIntroductoryPagesView];
}

@end


@interface IntroductoryPagesView : NSObject

- (instancetype)initNewPagesViewWithFrame:(CGRect)frame Images:(NSArray *)images andBtnTitles:(NSArray *)btnTitles andType:(NSInteger)guideType;


@end


@implementation IntroductoryPagesView

- (instancetype)initNewPagesViewWithFrame:(CGRect)frame Images:(NSArray *)images andBtnTitles:(NSArray *)btnTitles andType:(NSInteger)guideType
{
    if (self = [super initWithFrame:frame]) {
        self.imageArray = images;
        self.guideType = guideType;
        self.btnTitles = btnTitles;
        [self loadNewPageView];
    }
    return self;
}


- (void)loadNewPageView
{
    UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    scrollView.contentSize = CGSizeMake((self.imageArray.count + 1) * [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
    
    //设置反野效果，不允许反弹，不显示水平滑动条，设置代理为自己
    scrollView.pagingEnabled = YES;//设置分页
    scrollView.bounces = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.scrollEnabled = NO;
    scrollView.delegate = self;
    [self addSubview:scrollView];
    self.bigScrollView = scrollView;
    
    for (int i = 0; i < self.imageArray.count; i++) {
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.frame = CGRectMake(i * [UIScreen mainScreen].bounds.size.width, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
        NSString *imageName = self.imageArray[i];
                
        UIImage *img = [UIImage imageNamed:imageName];
        imageView.image = img;
        imageView.userInteractionEnabled = YES;
        [scrollView addSubview:imageView];
        
        UILabel *nextBtnLabel = [[UILabel alloc] initWithFrame:CGRectMake(([UIScreen mainScreen].bounds.size.width - 160) / 2, [UIScreen mainScreen].bounds.size.height - 120, 160, 50)];
        nextBtnLabel.tag = 500 + i;
        nextBtnLabel.text = self.btnTitles[i];
        nextBtnLabel.font = [UIFont systemFontOfSize:18];
        nextBtnLabel.backgroundColor = [UIColor colorWithRed:30.0/255.0 green:141.0/255.0 blue:255.0/255.0 alpha:1];
        nextBtnLabel.textColor = [UIColor whiteColor];
        nextBtnLabel.textAlignment = 1;
        nextBtnLabel.layer.cornerRadius = 25;
        nextBtnLabel.layer.masksToBounds = YES;
        [imageView addSubview:nextBtnLabel];
        UITapGestureRecognizer *nextTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchNextTap:)];
        [nextBtnLabel addGestureRecognizer:nextTap];
        nextBtnLabel.userInteractionEnabled = YES;
        
        NSString *textStr = @"跳过所有指导";
        UILabel *passAllLabel = [[UILabel alloc] initWithFrame:CGRectMake(([UIScreen mainScreen].bounds.size.width - 160) / 2, [UIScreen mainScreen].bounds.size.height - 60, 160, 30)];
        passAllLabel.textColor = [UIColor whiteColor];
        //下划线
        NSDictionary *attribtDic = @{
            NSUnderlineStyleAttributeName :[NSNumber numberWithInteger:0x01],
            NSUnderlineColorAttributeName : [UIColor whiteColor],
            NSFontAttributeName:[UIFont systemFontOfSize:14]
        };
        NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc] initWithString:textStr attributes:attribtDic];
        passAllLabel.attributedText = attribtStr;
        passAllLabel.textAlignment = 1;
        [imageView addSubview:passAllLabel];
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchPassTap:)];
        [passAllLabel addGestureRecognizer:tap];
        passAllLabel.userInteractionEnabled = YES;
        
    }
    
    UIPageControl *pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width / 2, [UIScreen mainScreen].bounds.size.height - 60, 0, 40)];
    pageControl.numberOfPages = self.imageArray.count;
    pageControl.hidden = YES; //隐藏底下的圆点
    pageControl.backgroundColor = [UIColor clearColor];
    [self addSubview:pageControl];
    
    self.pageControl = pageControl;
    

}




@end
